package com.cmict.data.form.api.util.SubUtil;

import cn.hutool.core.util.ObjectUtil;
import com.cmict.data.framework.common.pojo.CommonResult;
import com.cmict.data.form.api.service.SysCurrencyService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;


import static com.cmict.data.framework.common.pojo.CommonResult.success;

/**
 * @description: el-input组件规则
 * @author: qiaoyu
 * @create: 2022-07-18 22:57
 **/
public class ElColorUtil {

	@Resource
	private static SysCurrencyService sysCurrencyService;

	public static CommonResult rule (JSONObject personData , String value , int number) {
		String message = null;
		Boolean redata = true;
		JSONArray fields = personData.getJSONArray("fields");
		JSONObject field = fields.getJSONObject(number);
		JSONObject config = field.getJSONObject("__config__");
		String label = config.getString("label");
		//是否必填
		Boolean required = config.getBoolean("required");
		if(required && ObjectUtil.isEmpty(value)){
			message = label+"是必填项;";
			redata=false;
			//return success( label+"是必填项",false);
		}
		if(!value.contains("#")){
			message = "请输入正确的颜色标示;";
			redata=false;
		}
		if(!redata){
			return success( message,false);
		}
		return success( "通过",true);
	}


	/**
	 * 判断当前时间是否在[startTime, endTime]区间，注意时间格式要一致
	 *
	 * @param nowTime 当前时间
	 * @param startTime 开始时间
	 * @param endTime 结束时间
	 * @return
	 */
	public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
		if (nowTime.getTime() == startTime.getTime()
				|| nowTime.getTime() == endTime.getTime()) {
			return true;
		}

		Calendar date = Calendar.getInstance();
		date.setTime(nowTime);

		Calendar begin = Calendar.getInstance();
		begin.setTime(startTime);

		Calendar end = Calendar.getInstance();
		end.setTime(endTime);

		if (date.after(begin) && date.before(end)) {
			return true;
		} else {
			return false;
		}
	}
}

